<#if invalid?? && invalid>
<div class="alert alert-danger" role="alert">
	<strong>错误！</strong> 无效的合同信息！
</div>
<#else>
<form class="finish-contract-form" action="${request.contextPath}/contract/finish-contract/${cid}" method="post" enctype="multipart/form-data">
	<div class="row">
		<div class="col-md-12">
			<div class="form-group">
				<div class="input-group">
					<div class="input-group-addon">
						<div class="form-item-title">
							<span class="not-null-star">*</span> 竣工日期
						</div>
					</div>
					<input type="text" class="form-control not-empty datetimepicker" data-format="yyyy-MM-dd" data-foot="false" value="${end!''}" name="time" placeholder="请选择实际结束日期" readonly="readonly">
				</div>
			</div>
		</div>
		<div class="col-md-12">
			<div class="form-group">
				<div class="input-group">
					<div class="input-group-addon">
						<div class="form-item-title">
							<span class="not-null-star">*</span> 竣工资料
						</div>
					</div>
					<input type="file" name="file" class="hidden"> <input type="text" class="form-control not-empty file-show" placeholder="请选择相关文件。" readonly="readonly">
				</div>
			</div>
		</div>
		<div class="col-md-12">
			<div class="form-group">
				<div class="input-group">
					<div class="input-group-addon">
						<div class="form-item-title">备注</div>
					</div>
					<textarea rows="5" class="form-control" name="remark"></textarea>
				</div>
			</div>
		</div>
	</div>
	<hr>
	<div class="row">
		<div class="col-md-12 text-right">
			<div class="btn btn-primary btn-sm btn-submit">确定</div>
			&nbsp;
			<div class="btn btn-default btn-sm" onclick="Suredy.Modal.closeModal();">关闭</div>
		</div>
	</div>
</form>
<script type="text/javascript">
	require([ '${request.contextPath}/app/js/file.js', '${request.contextPath}/app/js/form-checker.js', 'suredyModal', 'suredyDatetimepicker', 'jqueryForm' ], function(File, formChecker, Modal) {
		File.init('<div class="form-group item">\
						<div class="input-group">\
							<div class="input-group-addon">\
								<div class="form-item-title">竣工资料</div>\
							</div>\
							<input type="file" name="file" class="hidden">\
							<input type="text" class="form-control form-data file-show" placeholder="请选择相关文件。" readonly="readonly">\
							<div class="btn input-group-addon file-remove">\
								<i class="icon-remove text-danger"></i>\
							</div>\
						</div>\
					</div>');

		$('form.finish-contract-form .btn-submit').on('click', function() {
			var form = $('form.finish-contract-form');

			// 校验表单
			if (!formChecker(form)) {
				return false;
			}

			var $this = $(this);

			if ($this.hasClass('disabled'))
				return false;

			$this.addClass('disabled');

			form.ajaxSubmit({
				dataType : "json",
				success : function(data, textStatus, jqXHR) {
					if (!data || !data.success) {
						var msg = (data && data.msg) || '竣工操作失败!';
						alert(msg);
						$this.removeClass('disabled');
						return false;
					}

					Suredy.refreshContent('${cid}', [ '#tab1' ]);

					Modal.closeModal();
				},
				error : function(jqXHR, textStatus, errorThrown) {
					alert('竣工操作失败!\n' + errorThrown);
					$this.removeClass('disabled');
					return false;
				}
			});
		});
	});
</script>
</#if>
